package com.scsj.supermarket.view.activity.settingmodel;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.alibaba.fastjson.JSONObject;
import com.scsj.supermarket.R;
import com.scsj.supermarket.base.SetRealNameBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.config.RxSPConfig;
import com.scsj.supermarket.presenter.SetRealNamePresenter;
import com.scsj.supermarket.utils.SkipUtils;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.vondear.rxtools.RxSPTool;

import es.dmoral.toasty.Toasty;
import okhttp3.RequestBody;

/**
 * Created by Mr.zhang(Administrator) on 2018/6/8.
 * 实名认证
 */
public class RealNameAuthenticationActivity extends BaseActivity implements View.OnClickListener, SetRealNameBase.IView {
    /**
     * 请输入真实姓名
     */
    private EditText mEtRealName;
    /**  */
    private EditText mIdcardNoEt;
    /**
     * 提交
     */
    private Button mBtnCommit;
    private SetRealNamePresenter setRealNamePresenter;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_real_name_authentication);
        //ScreenAdapterTools.getInstance().loadView((ViewGroup) getWindow().getDecorView());
        //ScreenAdapterTools.getInstance().reset(this);//如果希望android7.0分屏也适配的话,加上这句
        initToolbar();
        setToolbarTitle("实名认证");
        hasBack(true);
        setRealNamePresenter = new SetRealNamePresenter(this);
    }

    @Override
    protected void initView() {

        mEtRealName = (EditText) findViewById(R.id.et_real_name);
        mIdcardNoEt = (EditText) findViewById(R.id.idcardNo_et);
        mBtnCommit = (Button) findViewById(R.id.btn_commit);
        mBtnCommit.setOnClickListener(this);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.btn_commit:
                JSONObject obj = new JSONObject();
                obj.put("idcard", mIdcardNoEt.getText());
                obj.put("truename", mEtRealName.getText());
                obj.put("username", RxSPTool.getString(this, RxSPConfig.USER_PHONE));
                RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=utf-8"), obj.toString());
                setRealNamePresenter.deliverData(body);

                break;
            default:
                break;
        }
    }

    @Override
    public void showSuccessMsg(String s, BaseBean addDABean) {
        Toasty.success(this, s).show();
        SkipUtils.toRealNameAuthenticationShow(this);
    }

    @Override
    public void showErrorMsg(String s) {
        Toasty.error(this, s).show();
    }
}
